package vertxTest;

import org.junit.Test;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;

import static com.stu.vertx.hello.utils.ConvertUtils.netSourceToBase64;

public class MyTest01 {

    @Test
    public void test01() {
        ArrayList<EQTCashDWEnquiryInfo> lvList = new ArrayList<>();

        EQTCashDWEnquiryInfo info01 = new EQTCashDWEnquiryInfo();
        info01.setId("1");
        info01.setCreateionTime("2020-01-03");
        EQTCashDWEnquiryInfo info02 = new EQTCashDWEnquiryInfo();
        info02.setId("2");
        info02.setCreateionTime("2020-01-07");
        EQTCashDWEnquiryInfo info03 = new EQTCashDWEnquiryInfo();
        info03.setId("3");
        info03.setCreateionTime("2020-01-01");

        lvList.add(info01);
        lvList.add(info02);
        lvList.add(info03);

        System.out.println(lvList);

        if (lvList.size() > 0) {
            Collections.sort(lvList, new Comparator<EQTCashDWEnquiryInfo>() {
                @Override
                public int compare(EQTCashDWEnquiryInfo o1, EQTCashDWEnquiryInfo o2) {
                    return o2.getCreateionTime().compareTo(o1.getCreateionTime());
                }
            });
        }
        System.out.println(lvList);

    }

    @Test
    public void test02() {
        int num = "a".compareTo("b");
        System.out.println(num);
    }

    @Test
    public void test03() {
        String str = "a,b,c,d,e";
        String[] strArr = str.split(",");
        System.out.println(Arrays.toString(strArr));
        for (int i = 0; i < strArr.length; i++) {
            System.out.println(strArr[i]);
        }
    }

    @Test
    public void test04() {
        ArrayList<HashMap<String, String>> lvList = new ArrayList<>();
        HashMap<String, String> map01 = new HashMap<>();
        map01.put("01", "01");
        map01.put("02", "02");
        map01.put("03", "03");
        map01.put("04", "04");
        map01.put("05", "05");
        lvList.add(map01);

        HashMap<String, String> map02 = new HashMap<>();
        map02.put("01", "011");
        map02.put("02", "022");
        map02.put("03", "033");
        map02.put("04", "044");
        map02.put("05", "055");
        lvList.add(map01);

        HashMap<String, String> map03 = new HashMap<>();
        map03.put("01", "01");
        map03.put("02", "02");
        map03.put("03", "03");
        map03.put("04", "04");
        map03.put("05", "05");
        lvList.add(map01);

        System.out.println(lvList);
    }

    @Test
    public void test06() {
        String str = "ORDER_BOU";
        String back = str.substring(str.indexOf("_") + 1);
        String font = str.substring(0, str.indexOf("_"));
        System.out.println(font);
        System.out.println(back);
    }

    @Test
    public void test07() throws ParseException {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String str = simpleDateFormat.format(date);
        System.out.println(str);
        Date parse = simpleDateFormat.parse(str);
        System.out.println(parse);
    }


    @Test
    public void test08() {
        System.out.println(aa() + "aaaaaaaaaa");


        String str = null;
        System.out.println("dsdsdsd" + str);
    }

    public String aa() {
        return null;
    }

    @Test
    public void test09() {
        System.out.println(System.getProperty("user.dir"));
    }

    @Test
    public void test10() throws Exception {
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("C:\\Users\\TTLGZ-073\\Desktop\\a.txt"));
        StringBuilder sb = new StringBuilder();
        sb.append("Test Case : " + "111111");
        sb.append("Test Time : " + "222222");
        sb.append("Test Data : " + "333333");
        sb.append("Test Response : " + "444444");
        sb.append("Test Passed : " + "555555");
        //- 缓冲区大小
        byte[] buffer = new byte[1024];
        //- 记录读入缓冲区的总字节数
        int len = 0;
        //- 如果到文件末尾则返回-1
        bos.write(sb.toString().getBytes(StandardCharsets.UTF_8));
        //- 将缓冲区的文件写出
        bos.flush();
        //- 释放资源
        bos.close();
    }

    @Test
    public void test11() throws Exception {
        // 普通的控制台输出
        //PrintStream ps = System.out;

        // 将输出重定向到文件
        //ps = new PrintStream(new BufferedOutputStream(new FileOutputStream("print.txt")), true);
        //System.setOut(ps);
        ByteArrayOutputStream mvByteArrayOutputStream = new ByteArrayOutputStream();
        System.setOut(new PrintStream(mvByteArrayOutputStream));
        System.out.println("Test Case : " + "111111");
        System.out.println("Test Time : " + "222222");
        System.out.println("Test Data : " + "333333");
        System.out.println("Test Response : " + "444444");
        System.out.println("Test Passed : " + "555555");


        PrintStream mvPrintStream = System.out;
        System.setOut(mvPrintStream);

        // 返回到控制台输出
        // System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), true));
    }

    @Test
    public void test12() {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date date = sdf.parse("xxxxx");
            System.out.println(date);

        } catch (ParseException e) {
            StringWriter lvErrorWriter = new StringWriter();
            e.printStackTrace(new PrintWriter(lvErrorWriter));
            System.out.println(lvErrorWriter.toString());
        }
    }


    @Test
    public void test13() {
        try {
            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("C://dsdsad//"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }


    @Test
    public void test14() {
        boolean flag = checkPhone("13068226453");
        System.out.println(flag);
    }

    public boolean checkPhone(String phone) {
        String TEL_REGEXP = "0?(13|14|15|18|17)[0-9]{9}";
        return Pattern.compile(TEL_REGEXP).matcher(phone).matches();
    }


    @Test
    public void test15() {
        BigDecimal bg = new BigDecimal("123456456.13");

        String s1 = bg.toPlainString();
        System.out.println(s1);
        System.out.println(s1 instanceof String);

        String s2 = String.valueOf(bg);
        System.out.println(s2);
        System.out.println(s2 instanceof String);
    }

    @Test
    public void test16() {
        System.out.println(SimpleDateFormat.class.getSimpleName());
    }

    /**
     * objects clone
     */
    @Test
    public void test17() throws CloneNotSupportedException {
        Person tom = new Person("1", "tom", "18");
        Person tom_clone = (Person) tom.clone();
        tom.setAge("19");
        System.out.println(tom);
        System.out.println(tom_clone);
    }


    @Test
    public void test18() {
        BigDecimal decimal = new BigDecimal(30);
        System.out.println(decimal.toPlainString());
        decimal = null;
        System.out.println(decimal.toPlainString());
    }


    @Test
    public void test19() {
        String code = netSourceToBase64("https://www1.hkexnews.hk/listedco/listconews/sehk/2021/0901/2021090102155_c.pdf", "GET");
        String newCode = "data:application/pdf;base64," + code;
        //System.out.println(newCode);
        System.out.println(newCode.split(":")[1].split(",")[1]);
    }

    @Test
    public void test20() {
        HashMap<String, Vector> stringVectorHashMap = new HashMap<>();
        Vector<HashMap<String, String>> hashMapVector = new Vector<>();
        HashMap<String, String> hashMap1 = new HashMap<>();
        hashMap1.put("1", "1");
        hashMap1.put("2", "2");
        hashMap1.put("3", "3");
        hashMap1.put("4", "4");
        hashMapVector.add(hashMap1);
        HashMap<String, String> hashMap2 = new HashMap<>();
        hashMap2.put("1", "1");
        hashMap2.put("2", "2");
        hashMap2.put("3", "3");
        hashMap2.put("4", "4");
        hashMapVector.add(hashMap2);
        System.out.println(hashMapVector);
        stringVectorHashMap.put("one", hashMapVector);
        System.out.println(stringVectorHashMap);
    }

    @Test
    public void test21() {
        String lvErrorCodeNode = null;
        if (lvErrorCodeNode == null || lvErrorCodeNode.toString().equals("")) {
            System.out.println(lvErrorCodeNode.toString());
        }
    }

    @Test
    public void test22() {
        String lvProspectusLink = "http://www1.hkexnews.hk/listedco/listconews/sehk/2021/0920/2021092000006_c.pdf";
        if (lvProspectusLink != null && lvProspectusLink != "") {
            // 如果不包含http或https，加上http
            if (lvProspectusLink.indexOf("http:") < 0 && lvProspectusLink.indexOf("https:") < 0) {
                lvProspectusLink = "http://" + lvProspectusLink;
            }
        }
        System.out.println("lvProspectusLink:" + lvProspectusLink);

        String lvProspectusLink2 = "https://www1.hkexnews.hk/listedco/listconews/sehk/2021/0920/2021092000006_c.pdf";
        if (lvProspectusLink2 != null && lvProspectusLink2 != "") {
            if (lvProspectusLink2.indexOf("http:") < 0 && lvProspectusLink2.indexOf("https:") < 0) {
                lvProspectusLink2 = "http://" + lvProspectusLink2;
            }
        }
        System.out.println("lvProspectusLink2:" + lvProspectusLink2);

        String lvProspectusLink3 = "www1.hkexnews.hk/listedco/listconews/sehk/2021/0920/2021092000006_c.pdf";
        if (lvProspectusLink3 != null && lvProspectusLink3 != "") {
            if (lvProspectusLink3.indexOf("http:") < 0 && lvProspectusLink3.indexOf("https:") < 0) {
                lvProspectusLink3 = "http://" + lvProspectusLink3;
            }
        }
        System.out.println("lvProspectusLink3:" + lvProspectusLink3);
    }

    @Test
    public void test23() {
        String lvProspectusLink = "http://www1.hkexnews.hk/listedco/listconews/sehk/2021/0920/2021092000006_c.pdf";
        if (lvProspectusLink != null && lvProspectusLink != "") {
            // 如果不包含http或https，加上http
            if (lvProspectusLink.startsWith("http:") && lvProspectusLink.startsWith("https:")) {
                lvProspectusLink = "http://" + lvProspectusLink;
            }
        }
        System.out.println("lvProspectusLink:" + lvProspectusLink);

        String lvProspectusLink2 = "https://www1.hkexnews.hk/listedco/listconews/sehk/2021/0920/2021092000006_c.pdf";
        if (lvProspectusLink2 != null && lvProspectusLink2 != "") {
            if (lvProspectusLink2.indexOf("http:") < 0 && lvProspectusLink2.indexOf("https:") < 0) {
                lvProspectusLink2 = "http://" + lvProspectusLink2;
            }
        }
        System.out.println("lvProspectusLink2:" + lvProspectusLink2);

        String lvProspectusLink3 = "www1.hkexnews.hk/listedco/listconews/sehk/2021/0920/2021092000006_c.pdf";
        if (lvProspectusLink3 != null && lvProspectusLink3 != "") {
            if (lvProspectusLink3.indexOf("http:") < 0 && lvProspectusLink3.indexOf("https:") < 0) {
                lvProspectusLink3 = "http://" + lvProspectusLink3;
            }
        }
        System.out.println("lvProspectusLink3:" + lvProspectusLink3);
    }


    @Test
    public void test24() {
        String lvFiniconsentLink = "http://www1.hkexnews.hk/listedco/listconews/sehk/2021/0920/2021092000006_c.pdf";
        lvFiniconsentLink = lvFiniconsentLink == null || "".equals(lvFiniconsentLink) ? "#" : lvFiniconsentLink;
        System.out.println(lvFiniconsentLink);
    }

    @Test
    public void test25() {
        Hashtable<String, String> hashtable = new Hashtable<>();
        //hashtable.put(null,"11");
        //hashtable.put("11",null);
        hashtable.put("11", "");
        String marketId = "HKEX";
        String stockCode = "01535";
        System.out.println(marketId.concat("|").concat(stockCode.toUpperCase()));
    }

    @Test
    public void test26() {
        //System.out.println(String.valueOf(null));
        System.out.println(String.valueOf("null"));

        if ("Y".equalsIgnoreCase(null)) {
            System.out.println("true");
        }

        if (isInteger("200003933")) {
            System.out.println("是整数");
        }
    }
    public boolean isInteger (String param){
        Pattern pattern = Pattern.compile("[0-9]+");
        return pattern.matcher(param).matches();
    }


    @Test
    public void test27() {
        //System.out.println(Double.parseDouble("")); // NULL POINTER
        //System.out.println(new BigDecimal("1.2424"));
        System.out.println(Double.parseDouble("2.000000"));
        System.out.println(Double.parseDouble("2.220000"));

       // System.out.println(addAndRound("", "", 5));

    }
    public static String addAndRound(String s1, String s2, int scale) {
        BigDecimal b1 = new BigDecimal(s1);
        BigDecimal b2 = new BigDecimal(s2);
        return b1.add(b2).setScale(scale, BigDecimal.ROUND_HALF_UP).toPlainString();
    }

    @Test
    public void test28() {
        String imgBase64 = "";
        String[] imgs = imgBase64.split("data:");
        for (int i = 1; i < imgs.length; i++) {
            String img = imgs[i];
            img = img.substring(img.indexOf(",") + 1).replace(",","");
            System.out.println(img);
        }
    }

    @Test
    public void test29() {
        Boolean aBoolean = new Boolean("true");
        System.out.println(aBoolean);
    }

    private  final static String str1= "true";

    @Test
    public void test30() {
        System.out.println(str1.equals("true"));
        System.out.println("true".equals("true"));
    }

    @Test
    public void test31() {
        System.out.println(50 / 10 - Math.abs(50) * 100);
    }

    @Test
    public void test32() {
        String lvTranType = "ORDER_BOU";
        String lvSubTranType = lvTranType.substring(lvTranType.indexOf("_") + 1);
        lvTranType = lvTranType.substring(0, lvTranType.indexOf("_"));
        System.out.println(lvSubTranType);
        System.out.println(lvTranType);
    }

    @Test
    public void test33() throws IOException {
        FileOutputStream fos = new FileOutputStream("c:\\kk.txt");
        fos.write("1".getBytes());
    }

    @Test
    public void test34()  {
        System.out.println(UUID.randomUUID().toString().replaceAll("-", ""));
        System.out.println(UUID.randomUUID().toString().replaceAll("-", "").substring(0, 16));
    }



}
